package com.lingjtx.common.redis.stream;

import org.springframework.beans.factory.InitializingBean;

/**
 * 示例消费者监听器
 */
//@Component
public class ExampleListener implements RedisEventListener<ExampleEvent>, InitializingBean {

    private final RedisEventListenerRegistry registry;

    public ExampleListener(RedisEventListenerRegistry registry) {
        this.registry = registry;
    }

    /**
     * redis stream 监听器接收数据
     * 在 spring 本地事件监听，可以使用 @EventListener 来监听数据，进行数据消费
     *
     * @EventListener public void onMessage(ExampleEvent event) {
     * System.out.println(">>> [Spring Event] 一条测试数据：" + event.getUsername());
     * }
     */
    @Override
    public void onMessage(ExampleEvent event) {
        System.out.println("🐰 [Redis Listener] 一条测试数据: " + event.getUsername());
    }

    @Override
    public Class<ExampleEvent> getEventType() {
        return ExampleEvent.class;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        registry.register(this);
    }
}
